﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using XDL.Framework.Input;

namespace XDL.Framework.Screens
{
    /// <summary>
    /// Base class for input-based UI
    /// </summary>
    /// <remarks>
    /// Loosely based on the System.Windows.UIElement class (WPF framework).
    /// </remarks>
    public abstract class UIElement
    {
        bool m_enabled = true;

        /// <summary>
        /// Gets or sets whether this menu entry can be selected.
        /// </summary>
        /// <remarks>
        /// An non-selectable <see cref="MenuItem"/> is usefull to display text-only in a menu screen.
        /// </remarks>
        public bool Enabled
        {
            get { return m_enabled; }
            set { m_enabled = value; }
        }

        /// <summary>
        /// Updates the menu entry.
        /// </summary>
        public virtual void Update(
            MenuScreen screen, 
            bool isSelected,
            GameTime gameTime)
        {
            // does nothing
        }

        /// <summary>
        /// Load graphical content.
        /// </summary>
        public virtual void LoadContent()
        {
            // does nothing
        }

        /// <summary>
        /// Attempts to set focus to this element.
        /// </summary>
        /// <returns>Default implementation returns false.</returns>
        public virtual bool Focus()
        {
            return false;
        }

        /// <summary>
        /// Draws the UIElement
        /// </summary>
        /// <param name="screen"></param>
        /// <param name="position"></param>
        /// <param name="isSelected"></param>
        /// <param name="gameTime"></param>
        public abstract void Draw(MenuScreen screen, Vector2 position,
                                 bool isSelected, GameTime gameTime);

        /// <summary>
        /// Returns the size of the control.
        /// </summary>
        /// <returns></returns>
        public abstract Vector2 Measure();

        /// <summary>
        /// Handles user input.
        /// </summary>
        /// <param name="input"></param>
        public abstract void HandleInput(InputState input);
    }
}
